package com.sunflower.bath.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.sunflower.framework.utils.JsonResult;
import org.sunflower.framework.utils.StringUtils;

import com.sunflower.bath.model.JobExecution;
import com.sunflower.bath.service.IJobExecutionService;
@Controller
@RequestMapping(value = "jobexecution")
public class JobExecutionController {
	@Autowired
	private IJobExecutionService jobExecutionService;
	private final Logger logger = LoggerFactory.getLogger(getClass());
	/**
	 * 新增批处理任务
	 * @param map
	 * @param JobExecution
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/addjobexecution", method = { RequestMethod.GET })
	public JsonResult addJobExecution(ModelMap map, JobExecution model){
		JsonResult jr = JsonResult.newInstance();
		if(StringUtils.isNullOrBlank(model.getJobName())){
			logger.error("任务名称不能为空");
			return jr.declareFailure("任务名称不能为空");
		}
		if(StringUtils.isNullOrBlank(model.getJobDec())){
			logger.error("任务描述不能为空");
			return jr.declareFailure("任务描述不能为空");
		}
		if(StringUtils.isNullOrBlank(model.getJobType())){
			logger.error("任务类型不能为空");
			return jr.declareFailure("任务类型不能为空");
		}
		String reslut = jobExecutionService.insert(model);
		map.put("jobExecution", model);
		return reslut==null?jr.declareSuccess():jr.declareFailure(reslut);
	}
}
